package com.devicetracker;

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.Parameter;
import com.restfb.types.FacebookType;

/**
 * This class has utility functions related to facebook
 * @author pradyumna
 *
 */
public class FbUtils {
	
	/**
	 * This function will publish the location with provided accessToken.
	 * @param accessToken
	 * @param lat
	 * @param lang
	 * @param message
	 * @return
	 * @throws Exception
	 */
	public String publishPost(String accessToken,String lat,String lang,String message) throws Exception{
		FacebookType publishMessageResponse;
		try {
			FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
			publishMessageResponse = facebookClient.publish("me/feed", FacebookType.class,
			    Parameter.with("link", getMapUrl(lat,lang)),Parameter.with("message",message));
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}
		return publishMessageResponse.getId();		
	}

	/**
	 * This function will return static URL of Google Maps
	 * @param lat
	 * @param lang
	 * @return
	 */
	public String getMapUrl(String lat,String lang){
		return "http://maps.google.com/maps/api/staticmap?center="+lat+","+lang+"&zoom=13&markers="+lat+","+lang+"&size=500x300&sensor=true";
	}
	
}
